///////////////////////////////////////////////////////////
//  CCreateTemplateView.h
//  Implementation of the Class CCreateTemplateView
//  Created on:      21-Sep-2013 9:37:15 AM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#if !defined(EA_48DD8977_2B95_4dbf_9B82_7D2E4AA28A07__INCLUDED_)
#define EA_48DD8977_2B95_4dbf_9B82_7D2E4AA28A07__INCLUDED_

#include "IViewCtrl.h"
#include "IPage.h"
#include "IWindowDirector.h"

using namespace Data;

namespace UI
{
class CCreateTemplateView : public IViewCtrl
{

public:
  CCreateTemplateView(IWindowDirector* director);
	virtual ~CCreateTemplateView();
	virtual IViewCtrl::ViewType GetType() const;
	virtual void Initialize();
	virtual void Refresh();
	virtual void ShowView(bool show = true);
	bool OnClickedAdd(CButton* button);
	void OnClickedBack();
	void OnClickedSave();
	bool OnClickedChoices(CButton* button);
	void OnClickedSwap();
	bool OnClickedRemove(CButton* button);
	bool OnClickedEdit(CButton* button);
	bool OnClickedInsert(CButton* button);
	void CreatePage();
	IPage* GetPage();
	void SetPage(IPage* page);
  void NewPage();
	void RemovePage();
  void SetTitleView(const std::string& text);
  IObject* GetCurrentData();
  void AppendData(IObject* data);
  void InsertData(IObject* data);
  void EditCurrentNameData(const std::string& text);

private:
  void AddRow(IObject* item, std::string labelName, std::string labelText);
  void AddTableRow(IObject* item, bool isChild = false);
  CTableItemPtr CreateTableRow(IObject* item, bool isChild = false);

private:
  bool OnClickedNevigationBar(CNavigationBar* navigationBar, int button);
  bool OnClickedToolBar(CToolBar* toolBar, int button);
  bool OnSelectedTable(CTable* table, int tab);
  bool OnAlertButtonClick(CAlertDialog* dialog, EAlertDialogButton button);


private:
	IViewCtrl::ViewType   m_type;
	IWindowDirector*      m_parrentWnd;
	IPage*                m_templatePage;
  CNavigationBarPtr     m_navigationBar;
  CToolBarPtr           m_toolBar;
  CTablePtr             m_table;
  int                   m_currentRow;
  IObject*              m_currentItem;
  std::vector< std::pair< IObject*, CTableItemPtr > > m_tableRows;
  /** Collection index of page object
  * first = index in row table
  * second.first = index item in page object
  * second.second = index item in header object
  */
  std::map< int, std::pair< int, int > >  m_pageIndexs; 
  CAlertDialogPtr       m_alretDlg;
};
}
#endif // !defined(EA_48DD8977_2B95_4dbf_9B82_7D2E4AA28A07__INCLUDED_)
